// pages/user/order/order.js
import API from "../../../service/API";

Page({

    /**
     * 页面的初始数据
     */
    data: {
        status: [{
            title: "预约中",
            value: 1
        }, {
            title: "预约成功",
            value: 2
        }, {
            title: "预约失败",
            value: 3
        }],
        componentLoad: {
            api: API.productOrderList,
            params: {},
            list: [],
            loading: true,
            reset: false
        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /*
    * tabs切换
    * */
    onTabsChange: function (e) {
        const that = this;
        clearTimeout(that._onTabsChange);
        that._onTabsChange = setTimeout(function () {
            let {index} = e.detail;
            let status = that.data.status;
            that.setData({
                "componentLoad.params": {status: status[index].value},
                "componentLoad.list": [],
                "componentLoad.reset": true,
            })
        }, 300)
    },

    /*
    * 监听列表加载
    * */
    onLoadList: function (e) {
        const that = this;
        let {success, result} = e.detail;
        if (success) {
            let list = that.data.componentLoad.list;
            let isReset = that.data.componentLoad.reset;
            let newList = result.map(function (item) {
                return {
                    id: item.id,
                    name: item.name,
                    value: item.value,
                    allvalue: item.allvalue,
                    limit_time: item.limit_time,
                    order_status: parseInt(item.order_status)
                }
            })
            list = isReset ? newList : list.concat(newList);
            that.setData({"componentLoad.list": list}, function () {
                that.setData({
                    "componentLoad.reset": false,
                    "componentLoad.loading": false
                })
            })
        } else {
            that.setData({
                "componentLoad.reset": false,
                "componentLoad.loading": false
            })
        }
    },

    /*
    * 点击产品
    * */
    bindItem: function (e) {
        let id = e.currentTarget.dataset.id;
        console.log(id)
        console.log(e)
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        this.setData({"componentLoad.loading": true})
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})